<?php
header("Content-Type:text/html; charset=utf-8");

function SearchCronJobsUserTip($email){
$SearchCronJobsUserTip= mysql_query("SELECT * FROM xige_user WHERE email='$email'");
$SearchCronJobsUserTip=mysql_fetch_array($SearchCronJobsUserTip);
return $SearchCronJobsUserTip['tip'];
}

function SearchCronJobsUserSet($email,$num){
$SearchCronJobsUserSet = mysql_query("SELECT * FROM xige_info WHERE email='$email'");
$SearchCronJobsUserSet=mysql_fetch_array($SearchCronJobsUserSet);
if ($num==0){
$SearchCronJobsUserSet=$SearchCronJobsUserSet['sidnew'];
}elseif($num==1){
$SearchCronJobsUserSet=$SearchCronJobsUserSet['emailsend'];
}elseif($num==2){
$SearchCronJobsUserSet=$SearchCronJobsUserSet['reply'];
}elseif($num==3){
$SearchCronJobsUserSet=$SearchCronJobsUserSet['replyinfo'];
}elseif($num==4){
$SearchCronJobsUserSet=$SearchCronJobsUserSet['qqnum'];
}else{
$SearchCronJobsUserSet=$SearchCronJobsUserSet['length'];
}
return $SearchCronJobsUserSet;
}

function Post_main($curl,$curlPost){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$curl);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
$data=curl_exec($ch);
curl_close($ch);
return $data;
}



function CronJobs($servername){

$result_cronjobs=mysql_query("SELECT * FROM $servername ");
while($cronjobs=mysql_fetch_array($result_cronjobs)){
$email=$cronjobs['email'];
$qid=$cronjobs['qid'];
$warn=$cronjobs['warn'];
$warnup=$warn+1;
$time=time();

if (SearchCronJobsUserTip($cronjobs['email'])==1){

$cronjobsurl=file_get_contents("http://pt.3g.qq.com/s?aid=nLogin3gqqbysid&3gqqsid=".$cronjobs['sid']."");

file_get_contents("http://q32.3g.qq.com/g/s?sid=".$cronjobs['sid']."&s=10&aid=chgStatus");

if (preg_match("/系统繁忙|sid已经过期/",$cronjobsurl)){

if ($warn>=300){
$qqnum=SearchCronJobsUserSet($cronjobs['email'],4)-1;
$length=(time() - $cronjobs['adddate']) + SearchCronJobsUserSet($cronjobs['email'],5);
mysql_query("Update xige_info set qqnum='$qqnum',length='$length' where email='$email'");
mysql_query("DELETE FROM xige_qqlist WHERE email='$email' and qid='".$qid."'");
mysql_query("DELETE FROM $servername WHERE email='$email' and qid='".$qid."'");
}else{
mysql_query("Update xige_qqlist set qqol='1',sidol='1',warn='$warnup' where email='$email' and qid='$qid'");
mysql_query("Update $servername set warn='$warnup' where email='$email' and qid='$qid'");
}

if (SearchCronJobsUserSet($cronjobs['email'],1)==1){
if (date("Y-m-d",$time)!=date("Y-m-d",$cronjobs['emailtime'])){
mysql_query("Update $servername set emailtime='$time' where email='$email' and qid='$qid'");
SendEmailUser($cronjobs['qq'],$email);
}
}

}else{
mysql_query("Update xige_qqlist set qqol='0',sidol='0',warn='0' where email='$email' and qid='$qid'");
mysql_query("Update $servername set warn='0' where email='$email' and qid='$qid'");

}



if (SearchCronJobsUserSet($cronjobs['email'],0)==1){

$out=addqq($cronjobs['qq'],$cronjobs['mima']);
if(preg_match("/登录3GQQ成功/",$out)){
$out=explode('sid=',$out);
$sid=substr($out[1],0,24);
mysql_query("Update $servername set sid='$sid' where email='$email' and qid='$qid'");
mysql_query("Update xige_qqlist set sid='$sid' where email='$email' and qid='$qid'");
}
}

}else{

$cronjobsurl=file_get_contents("http://pt.3g.qq.com/s?aid=nLogin3gqqbysid&3gqqsid=".$cronjobs['sid']."");
file_get_contents("http://q32.3g.qq.com/g/s?sid=".$cronjobs['sid']."&s=10&aid=chgStatus");
if (preg_match("/系统繁忙|sid已经过期/",$cronjobsurl)){

if ($warn>=300){
$qqnum=SearchCronJobsUserSet($cronjobs['email'],4)-1;
$length=(time() - $cronjobs['adddate']) + SearchCronJobsUserSet($cronjobs['email'],5);
mysql_query("Update xige_info set qqnum='$qqnum',length='$length' where email='$email'");
mysql_query("DELETE FROM xige_qqlist WHERE email='$email' and qid='".$qid."'");
mysql_query("DELETE FROM $servername WHERE email='$email' and qid='".$qid."'");
}else{
mysql_query("Update xige_qqlist set qqol='1',sidol='1',warn='$warnup' where email='$email' and qid='$qid'");
mysql_query("Update $servername set warn='$warnup' where email='$email' and qid='$qid'");
}
}else{

mysql_query("Update xige_qqlist set qqol='0',sidol='0' where email='$email' and qid='$qid'");
mysql_query("Update $servername set warn='0' where email='$email' and qid='$qid'");
}

}

sleep(0.1);
}


}

?>